<#assign ctx=request.contextPath />
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/static/layuiadmin/layui/css/layui.css" media="all">

    <link rel="stylesheet" href="${ctx}/static/layuiadmin/style/admin.css" media="all">
</head>
<body>
<form class="layui-form" action="" id="school">
    <div class="layui-form" lay-filter="layuiadmin-form-school" id="layuiadmin-form-school" style="padding: 20px 0 0 0;">

        <input type="hidden" name="id" id="id"   autocomplete="off" class="layui-input">


        <div class="layui-form-item">
        <label class="layui-form-label">国家</label>
        <div class="layui-input-block" style="width:800px">
        <select id="countryId" name="countryId" lay-verify="required" style="width:600px">
        <option value=""></option>
        </select>
        </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block" style="width:800px">
                <input type="text" name="title" id="title" lay-verify="required" placeholder="请输入..." autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">跳转页面</label>
            <div class="layui-input-block" style="width:800px">
                <input type="text" name="moreUrl" id="moreUrl" lay-verify="required" placeholder="请输入..." autocomplete="off" class="layui-input">
            </div>
        </div>

        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">内容</label>-->
            <!--<div class="layui-input-block" style="width:800px">-->
                <!--<textarea name="requires" id="requires" placeholder="请输入内容" class="layui-textarea"></textarea>-->
            <!--</div>-->
        <!--</div>-->

        <div class="layui-form-item">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block" style="width:800px">

                <textarea id="requires" name="requires" lay-verify="requires" style="display: none;"></textarea>

            </div>

        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">封面图片</label>
            <button type="button" class="layui-btn" id="test3">图片上传</button>
            <div class="layui-input-block">
                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;max-width: 300px;">
                    预览图：
                    <div class="layui-upload-list" id="demo3"></div>
                    <img class="layui-upload-img" id="demo4" style="width:150px;height:150px">
                    <input type="hidden" id="imgUrl" name="imgUrl" value="">
                    <!--img_index-->
                </blockquote>
            </div>
        </div>

        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="LAY-school-front-submit" id="LAY-school-front-submit" value="确认">
        </div>
    </div>
</form>
<script src="${ctx}/static/layuiadmin/layui/layui.js"></script>
<script>
    var ctx = "${ctx}";
    layui.config({
        base: ctx + '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'upload','layedit'], function(){
        var $ = layui.$
            ,form = layui.form
            ,layedit = layui.layedit
            ,upload = layui.upload ;
        var infoDetailEdit = layedit.build('requires'); //建立编辑器;
        form.verify({
            requires: function(value) {
                return layedit.sync(infoDetailEdit);
            }
        });
        // var infoDetailEdit = layedit.build('condition'); //建立编辑器;
        // form.verify({
        //     condition: function(value) {
        //         return layedit.sync(infoDetailEdit);
        //     }
        // });
        // setTimeout(function () {
        //     $()
        // },1000)

        $.ajax({
            //几个参数需要注意一下
            type: "get",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            // contentType : 'application/json; charset=UTF-8',
            url: ctx +"/country/findList/" ,//url
            // async : false,
            data: {
                hasSchool:1
            },
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.code == 1) {
                    for (var i=0;i<result.reObj.content.length;i++){
                        $('#countryId').append(new Option(result.reObj.content[i].name,result.reObj.content[i].id));// 下拉菜单里添加元素

                    }
                    form.render();
                }
            },
            error : function(e) {
                layer.msg('出错了');
            }
        });

        upload.render({
            elem: '#test3'
            // ,url: ctx +'/file/uploadFile'
            ,url: ctx +'/file/uploadFile'

            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo4').attr('src', result); //图片链接（base64）
                    //  $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img" style="width:150px;height:150px">')
                });
            }
            ,done: function(res){
                //上传完毕
                var url=res.files[0].absoluteFileUrl;
//           console.log(res);
                $('#imgUrl').val(url);
            }
        });





    })
</script>
</body>
</html>